<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="96px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">

          <el-col :lg="4" :md="4">
            <el-form-item label="支付类型">
              <el-select
                clearable
                v-model="where.pay_type"
                placeholder="请选择"
                class="ele-fluid">
                <el-option label="余额购买" value="2"/>
                <el-option label="微信支付" value="1"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="4" :md="4">
            <el-form-item label="订单状态">
              <el-select
                clearable
                v-model="where.status"
                placeholder="请选择"
                class="ele-fluid">
                <el-option label="已退款" value="3"/>
                <el-option label="未支付" value="0"/>
                <el-option label="已完成" value="4"/>
              </el-select>

            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="4">
            <el-form-item label="用户手机号:">
              <el-input
                clearable
                v-model="where.mobile"
                placeholder="用户手机号"/>
            </el-form-item>
          </el-col>

          <el-col :lg="4" :md="4">
            <el-form-item label="包厢名称:">
              <el-input
                clearable
                v-model="where.name"
                placeholder="包厢名称"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :lg="4" :md="4">

            <el-form-item label="日期:" prop="add_time">
              <el-date-picker
                type="date"
                clearable
                v-model="where.add_time"

                placeholder="请输入开始时间"/>

            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-date-picker
              type="date"
              clearable
              v-model="where.end_time"
style="margin-left: 96px;"
              placeholder="请输入结束时间"/>


          </el-col>
     <el-col :lg="6" :md="12">
       <div class="ele-form-actions" style="margin-right: 118px;">
         <el-button
           type="primary"
           icon="el-icon-search"
           class="ele-btn-icon"
           style=" margin-top: 10px;"
           @click="reload">查询
         </el-button>
         <el-button @click="reset">重置</el-button>
       </div>
     </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">

          <el-button
            size="small"
            type="success"
            icon="el-icon-download"
            class="ele-btn-icon"
            @click="exportExcel"
            v-if="permission.includes('sys:order:export')">导出
          </el-button>
        </template>


        <!-- 1正常 0  冻结 -->
        <template slot="status" slot-scope="{row}">
          <el-tag v-if="row.status === 1" type="success" size="small">未使用</el-tag>
          <el-tag v-if="row.status === 0" type="danger" size="small">未支付</el-tag>
          <el-tag v-if="row.status === 2" type="warning" size="small">进行中</el-tag>
          <el-tag v-if="row.status === 4" type="warning" size="small">已完成</el-tag>
          <el-tag v-if="row.status === 3" type="warning" size="small">已退款</el-tag>
        </template>

        <template slot="pay_status" slot-scope="{row}">
          <el-tag v-if="row.pay_status === 1" type="success" size="small">已支付</el-tag>
          <el-tag v-if="row.pay_status === 0" type="danger" size="small">未支付</el-tag>
          <el-tag v-if="row.pay_status === 3" type="warning" size="small">已退款</el-tag>
        </template>
        <template slot="pay_type" slot-scope="{row}">
          <el-tag v-if="row.pay_type === 1" type="success" size="small">微信支付</el-tag>

          <el-tag v-if="row.pay_type === 2" type="warning" size="small">余额支付</el-tag>
        </template>
        <template slot="if_fz" slot-scope="{row}">
         <el-tag v-if="row.if_fz === 1" type="warning" size="small">分账中</el-tag>
         <el-tag v-if="row.if_fz === 2" type="success" size="small">已分账</el-tag>
         <el-tag v-if="row.if_fz === 0" type="danger" size="small">否</el-tag>

        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">


          <el-popconfirm
            class="ele-action"
            title="确定要释放订单吗？"
            @confirm="remove(row)">
            <el-link
              type="danger"
              slot="reference"
              :underline="false"
              icon="el-icon-delete"
              v-if="permission.includes('sys:order:delete')">释放
            </el-link>
          </el-popconfirm>

        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->

  </div>
</template>

<script>
import {mapGetters} from "vuex";


export default {
  name: 'ExamUsercrad',

  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/renewalorder/index',
      // 表格列配置
      columns: [
        // {
        //   columnKey: 'selection',
        //   type: 'selection',
        //   width: 45,
        //   align: 'center',

        // },
        // {
        //   prop: 'id',
        //   label: 'ID',
        //   showOverflowTooltip: true,
        // minWidth: 80,
        // align: 'center',
        // fixed: "left"

        // },
        // {
        //   prop: 'nickname',
        //   label: '用户昵称',
        //   showOverflowTooltip: true,
        //   minWidth: 200,
        //   align: 'center',

        // },
        {
          prop: 'mobile',
          label: '用户手机号',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',

        },
        {
          prop: 'room_name',
          label: '门店名称',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
        },

        {
          prop: 'name',
          label: '包厢名称',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'pay_type',
          label: '支付类型',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
          slot: 'pay_type',
        },
        {
          prop: 'price',
          label: '价格',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },

        {
          prop: 'pay_price',
          label: '真实支付金额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },


        {
          prop: 'create_time',
          label: '下单时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          prop: 'add_time',
          label: '开始时间',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          prop: 'end_time',
          label: '到期时间',
          ortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },


        {
          prop: 'shi',
          label: '预定时长',
          showOverflowTooltip: true,
          minWidth: 50,
          align: 'center',

        },
        // {
        //   prop: 'notes',
        //   label: '备注',
        //   showOverflowTooltip: true,
        //   minWidth: 200,
        //   align: 'center',
        // },


        {
          prop: 'balance',
          label: '使用余额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'coupon_id',
          label: '优惠卷抵扣',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },


        {
          prop: 'status',
          label: '状态',
          align: 'center',
          width: 100,
          resizable: false,
          slot: 'status',
        },
        {
          prop: 'id',
          label: '编号',
          align: 'center',
          width: 100,
          resizable: false,

        },


        {
          prop: 'pay_time',
          label: '支付时间',
          showOverflowTooltip: true,
          minWidth: 200,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        {
          prop: 'order_on',
          label: '订单号',
          align: 'center',
          width: 250,
          resizable: false,

        },
        {
          prop: 'transaction_id',
          label: '支付单号',
          align: 'center',
          width: 250,
          resizable: false,

        },
        {
          prop: 'if_fz',
          label: '是否分账订单',
          align: 'center',
          width: 250,
          resizable: false,
          slot: 'if_fz',
        },
      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      typeList: [],

      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showEdits: false,
    };
  },

  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {

      this.current = row;
      this.showEdit = true;
    },

    /* 显示编辑 */
    openEdits(row) {

      this.current = row;
      this.showEdits = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/order/delete', {id: row.order_id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },

    getTypelist() {
      this.$http.get('/order/getTypelist').then(res => {
        if (res.data.code === 0) {
          this.typeList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的用户期限卡吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/cradorder/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },


    /* 更改1正常 0  冻结 3 */
    status(row) {
      const loading = this.$loading({lock: true});
      let params = Object.assign({
        "id": row.id,
        "status": row.status
      })
      this.$http.post('/cradorder/status', params).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
        } else {
          row.status = !row.status ? 1 : 2;
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
  }
}
</script>

<style scoped>
</style>
